﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using DLM.Infrastructure.Domain;

namespace DLM.Domain.Model
{
    public class User : IValidatableObject, IAggregateRoot
    {
        public User()
        {
            this.Bonus = new HashSet<Bonus>();
            this.Friend = new HashSet<Friend>();
            this.Invitation = new HashSet<Invitation>();
            this.Message = new HashSet<Message>();
            this.Photos = new HashSet<Photo>();
            this.Salutation = new HashSet<Salutation>();
            this.UserPartyAssociation = new HashSet<UserPartyAssociation>();
            this.UserView = new HashSet<UserView>();
        }

        public int UserID { get; set; }

        [Required(ErrorMessage = "用户昵称不允许为空")]
        public int AccountID { get; set; }

        [Required(ErrorMessage = "用户账号不允许为空")]
        public string AccountName { get; set; }

        [StringLength(20, ErrorMessage = "姓名长度不允许超过20位")]
        public string Name { get; set; }

        [Required(ErrorMessage = "性别不允许为空")]
        public Nullable<bool> Gender { get; set; }

        [Required(ErrorMessage = "出生日期不允许为空")]
        [DataType(DataType.DateTime, ErrorMessage = "出生日期格式不正确")]
        public Nullable<System.DateTime> Birthday { get; set; }

        [Required(ErrorMessage = "年龄不允许为空")]
        [RegularExpression(@"^[1-9]\d*$", ErrorMessage = "年龄格式不正确")]
        public Nullable<short> Age { get; set; }

        [Required(ErrorMessage = "现居住地不允许为空")]
        [StringLength(20, ErrorMessage = "最大长度为20")]
        public string Location { get; set; }

        [StringLength(30, ErrorMessage = "最大长度为20")]
        public string HomePlace { get; set; }

        [Required(ErrorMessage = "婚姻状况不允许为空")]
        [StringLength(8, ErrorMessage = "最大长度为20")]
        public string Marriage { get; set; }

        [StringLength(30, ErrorMessage = "最大长度为30")]
        public string NativePlace { get; set; }

        public string Stature { get; set; }

        [RegularExpression(@"^[1-9]\d*$", ErrorMessage = "体重格式不正确")]
        public Nullable<int> Weight { get; set; }

        [StringLength(10, ErrorMessage = "最大长度为10")]
        public string Education { get; set; }

        [StringLength(20, ErrorMessage = "最大长度为20")]
        public string Job { get; set; }

        [StringLength(15, ErrorMessage = "最大长度为15")]
        public string Income { get; set; }

        [StringLength(20, ErrorMessage = "最大长度为20")]
        public string Position { get; set; }

        [StringLength(10, ErrorMessage = "最大长度为30")]
        public string Industry { get; set; }

        [StringLength(30, ErrorMessage = "最大长度为20")]
        public string Car { get; set; }

        [StringLength(20, ErrorMessage = "最大长度为20")]
        public string Parents { get; set; }

        [StringLength(50, ErrorMessage = "最大长度为50")]
        public string Photo { get; set; }

        [RegularExpression(@"^(1(([35][0-9])|(47)|[8][01236789]))\d{8}$", ErrorMessage = "手机号码无效")]
        [StringLength(15, ErrorMessage = "最大长度为15")]
        public string Phone { get; set; }


        [RegularExpression(@"^[1-9]{1}\d{4,13}$", ErrorMessage = "QQ号码格式不正确")]
        [StringLength(18, ErrorMessage = "最大长度为18")]
        public string IM { get; set; }

        [StringLength(300, ErrorMessage = "最大长度为300")]
        public string Introduction { get; set; }

        public bool IsValidation { get; set; }

        public System.DateTime CreateDate { get; set; }

        public virtual Account Account { get; set; }
        public virtual ICollection<Bonus> Bonus { get; set; }
        public virtual ICollection<Friend> Friend { get; set; }
        public virtual ICollection<Invitation> Invitation { get; set; }
        public virtual ICollection<Message> Message { get; set; }
        public virtual ICollection<Photo> Photos { get; set; }
        public virtual ICollection<UserPartyAssociation> UserPartyAssociation { get; set; }
        public virtual ICollection<UserView> UserView { get; set; }
        public virtual ICollection<Salutation> Salutation { get; set; }

        public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
        {
            if (string.IsNullOrEmpty(AccountName))
            {
                yield return new ValidationResult("账户名不能为空！", new string[] { "AccountName" });
            }
            if (string.IsNullOrEmpty(Photo))
            {
                yield return new ValidationResult("用户头像必须上传！", new string[] { "Photo" });
            }

        }

    }
}
